package com.lulu.baselib.util.sp;

import android.content.Context;
import android.content.SharedPreferences;

import com.lulu.baselib.MyApplication;


/**
 * Author: XuChang
 * Date: 2019/7/31 16:58
 * Description:
 * History:
 */
public class SpManager {

    static final String SP_DEFAULT_NAME = "sp";

    static SharedPreferences sharedPreferences;
    static SharedPreferences.Editor editor;

    public static void init() {
        sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_DEFAULT_NAME, Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public static String getString(String key, String defaultValue) {
        return sharedPreferences.getString(key, defaultValue);
    }

    public static String getString(String key) {
        return getString(key, "");
    }

    public static void putString(String key, String value) {
        editor.putString(key, value);
        editor.apply();
    }

    public static boolean getBoolean(String key, boolean defaultValue) {
        return sharedPreferences.getBoolean(key, defaultValue);
    }

    public static void putBoolean(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.apply();
    }


}
